package com.erp.erp_servers.Drawback.impl;

import com.erp.erp_dao.Drawback.DrawbackDao;
import com.erp.erp_entitys.Drawback.entity.DrawbackEntity;
import com.erp.erp_entitys.Drawback.req.AddDrawbackReq;
import com.erp.erp_entitys.Drawback.req.QueryDrawbackReq;
import com.erp.erp_entitys.Drawback.vo.QueryDrawbackDetailVO;
import com.erp.erp_entitys.Drawback.vo.QueryDrawbackVO;
import com.erp.erp_servers.Drawback.DrawbackService;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zjk
 * @version 1.0
 * @description
 * @date 2021/1/12/012 22:51
 */
@Service
public class DrawbackServiceImpl implements DrawbackService {

    private final DrawbackDao drawbackDao;

    public DrawbackServiceImpl(DrawbackDao drawbackDao) {
        this.drawbackDao = drawbackDao;
    }

    @Override
    public Integer insertBillDeclareInfoToDrawback(Integer declareId) {
        return drawbackDao.insertBillDeclareInfoToDrawback(declareId);
    }

    @Override
    public Integer updateDrawbackByBillDeclareInfoId(Integer declareId) {
        return drawbackDao.updateDrawbackByBillDeclareInfoId(declareId);
    }

    @Override
    public Integer deleteDrawbackByBillDeclareInfoId(Integer declareId) {
        return drawbackDao.deleteDrawbackByBillDeclareInfoId(declareId);
    }

    @Override
    public PageInfo<QueryDrawbackVO> selectDrawbackByParam(QueryDrawbackReq req) {
        List<QueryDrawbackVO> drawbackVOList=drawbackDao.selectDrawbackByParam(req);

        return new PageInfo<>(drawbackVOList);
    }

    @Override
    public QueryDrawbackDetailVO selectDrawbackDetailByDrawbackId(Integer drawbackId) {
        return drawbackDao.selectDrawbackDetailByDrawbackId(drawbackId);
    }

    @Override
    public Integer updateDrawback(AddDrawbackReq req) {
        return drawbackDao.updateDrawback(req);
    }

    @Override
    public R  updateDrawbackStatus(Integer drawbackId, Integer drawbackStatus) {
        if (drawbackDao.updateDrawbackStatus(drawbackId,drawbackStatus)!=1){
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
        return R.build(ResultStatusEnum.SUCCESS);
    }

    @Override
    public R updateMarkColor(Integer drawbackId, String color) {
        if (drawbackDao.updateMarkColor(drawbackId,color)!=1){
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
        return R.build(ResultStatusEnum.SUCCESS);
    }

    @Override
    public DrawbackEntity selectByDeclareId(Integer declareId) {
        return drawbackDao.selectByDeclareId(declareId);
    }
}
